#include "folderStack.h"


int folderStackInit(folderStack_t *pStack) // 初始化栈
{
    pStack->pTop = NULL;
    pStack->stackSize = 0;
    return 0;
}

int push(folderStack_t *pStack,int file_id) // 入栈
{
    Node_t *newNode = (Node_t *)calloc(1,sizeof(Node_t));
    newNode->file_id = file_id;
    if(pStack->stackSize == 0)
    {
        pStack->pTop = newNode;
    }
    else
    {
        Node_t *curNode = pStack->pTop;
        newNode->pNext = curNode;
        pStack->pTop = newNode;
    }   
    pStack->stackSize ++;
    return 0;
}

int pop(folderStack_t *pStack) // 弹出栈顶
{
    Node_t *curNode = pStack->pTop;
    pStack->pTop = curNode->pNext;
    free(curNode);
    pStack->stackSize --;
    return 0;
}

int folderStackDestroy(folderStack_t *pStack) // 销毁栈
{
    while(pStack->stackSize != 0)
    {
        pop(pStack);
    }
    return 0;
}